package javabase.schoolwork.day6_11;

import java.util.Date;
import java.util.Random;
import java.util.Scanner;

/**
 * @author fance
 * @date 2018/6/12 9:05
 */
public class ATMClient {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Bank bank = Bank.getBank();
        bank.addAccounts(new Account("622608" + getEightNum(),"123",new Date(), User.GenUser));
        bank.addAccounts(new Account("622608" + getEightNum(),"123",new Date(), User.VipUser));
        bank.addAccounts(new Account("622608" + getEightNum(),"123",new Date(), User.PlatUser));
        bank.addAccounts(new Account("test","123",new Date(), User.PlatUser));

        ATM atm = new ATM("工商银行");
        while (true) {
            atm.menu();
            System.out.print("请选择操作:");
            int choose = scanner.nextInt();

            switch (choose) {
                case 1 : {
                    System.out.print("请输入账户名：");
                    String username = scanner.next();
                    System.out.print("请输入密码：");
                    String password = scanner.next();
                    atm.login(username, password);
                }  break;

                case 2 : {
                    atm.queryBalance();
                }  break;

                case 3 : {
                    System.out.print("请输入存钱金额：");
                    atm.deposit(scanner.nextDouble());
                }  break;

                case 4 : {
                    System.out.print("请输入取钱金额：");
                    atm.withDraw(scanner.nextDouble());
                }  break;
                case 5: {
                    atm.logout();
                    return;
                }

            }
        }
    }
    public static String getEightNum() {
        Random random = new Random(47);
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < 8; i++) {
            stringBuffer.append(random.nextInt(10));
        }
        return stringBuffer.toString();
    }
}
